<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    html {
      width: 100%;
      height: 100%;
    }

    body {
      width: 100%;
      height: 2400px;
    }

    div {
      width: 50px;
      height: 50px;
      background-color: pink;
      position: fixed;
      right: 30px;
      bottom: 30px;

      display: none;
    }

  </style>
</head>
<body>

  <div class="gotop"></div>


  <script src="./jquery/jquery.min.js"></script>
  <script>

    function scrollHandler() {
      const height = $(this).scrollTop()
      if (height >= 300) {
        $('.gotop').fadeIn(500)
      } else {
        $('.gotop').fadeOut(500)
      }
    }
    scrollHandler()
    $(window).scroll(scrollHandler)

    $('.gotop').click(function () {
      $('body, html').animate({ scrollTop: 0 }, 1000)
    })
  </script>
</body>
</html>
